package org.hbbTlias2025.controller;


import lombok.extern.slf4j.Slf4j;
import org.hbbTlias2025.pojo.Result;
import org.hbbTlias2025.utils.AliyunOSSOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
public class UploadController {

    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
        log.info("这个就是好宝宝的原始文件名字----{}", filename);

        try {
            String url = aliyunOSSOperator.upload(file.getBytes(), filename);
            log.info("这个就是好宝宝的url----{}", url);
            return Result.success(url);
        } catch (Exception e) {
            return Result.error(String.valueOf(e));
        }
    }


//    @RequestMapping("/upload")
//    public Result upload(String name, Integer age, MultipartFile file) throws IOException {
//        log.info("upload   ++++ {},{},{} +++", name, age, file);
//
//
//        String filename = file.getOriginalFilename();
//        String extension = "";
//        if (filename != null) {
//            extension = filename.substring(filename.lastIndexOf("."));
//        }
//        String newName = UUID.randomUUID().toString() + extension;
//
//        file.transferTo(new File("D:\\HBBjava\\upload\\" + newName));
//        return Result.success();
//    }


}
